/****************************************************************************************************/
/**
\file       Gpt.h
\brief      Gpt driver header file
\author     Equipo 1
\version    1.0
\date       09/02/2014
*/
/****************************************************************************************************/

#ifndef GPT_H        /*prevent duplicated includes*/ 
#define GPT_H  

/****************************************************************************************************
* Include files
*****************************************************************************************************/
#include "Std_Types.h"
#include "Gpt_Cfg.h"
#include "Mcu.h"
/****************************************************************************************************
* Definition of module wide MACROS / #DEFINE-CONSTANTS 
*****************************************************************************************************/

/** Periodic Interrupt Timer definitions */
#define    CNF_PIT_MICROTIMER_PERIOD            1000000
#define    CNF_PIT_TARGET_FREQ                  2000

/** Periodic Interrupt Timer macros */
#define    CNF_PIT_MICROTIMER_DIV               ( u8 ) ( ( mcal_mcu_busFrequency / CNF_PIT_MICROTIMER_PERIOD ) - 1 )
#define    CNF_PIT_VALUE                        ( ( CNF_PIT_MICROTIMER_PERIOD / CNF_PIT_TARGET_FREQ ) - 1 )

#define    CNF_PIT_MICROTIMER_PERIOD1           200000
#define    CNF_PIT_TARGET_FREQ1                 100000

#define    CNF_PIT_MICROTIMER1_DIV              ( u8 ) ( ( mcal_mcu_busFrequency / CNF_PIT_MICROTIMER_PERIOD1 ) - 1 )
#define    CNF_PIT_VALUE1                       ( ( CNF_PIT_MICROTIMER_PERIOD1 / CNF_PIT_TARGET_FREQ1 ) - 1 )

/****************************************************************************************************
* Module wide variables 
*****************************************************************************************************/

 typedef enum{
   
  GPT_CHANNEL_0,
  GPT_CHANNEL_1,
  GPT_CHANNEL_2,
  GPT_CHANNEL_3,
  GPT_CHANNEL_MAX

}Gpt_ChannelType;

  typedef enum{
    
    ONE,
    TWO,
    THREE
  }Gpt_ValueType;

/* Module Configuration Types */

typedef struct {
  Gpt_ChannelType ChannelID;
  u16 TimeInUs;
  u8 MicroTimerSource;
  tCallbackFunction PITChannel_Callback;
} PIT_ChannelConfigType;

typedef struct {
  u8 NumberOfPITChannels;
  u8 MicroTimerConfig0;
  u8 MicroTimerConfig1;
  PIT_ChannelConfigType *PIT_ChannelConfig;
  u8 dummyByte;
} PIT_DevicesConfigType;

typedef struct {
  PIT_DevicesConfigType *PIT_DevicesConfig;
  /* No TIM device defined */
} Gpt_DevicesConfigType;

typedef struct {
  u8 NumerOfGptDevices;
  Gpt_DevicesConfigType *Gpt_DevicesConfig;
  u8 dummyByte;
} Gpt_ConfigType;



extern const Gpt_ConfigType mcal_gpt_configuration;

/****************************************************************************************************
* Function Prototypes
*****************************************************************************************************/
void Gpt_Init( const Gpt_ConfigType* ConfigPtr );
void Gpt_StartTimer( Gpt_ChannelType Channel, Gpt_ValueType Value ) ;
void Gpt_StopTimer( Gpt_ChannelType Channel ) ;
void Gpt_EnableNotification( Gpt_ChannelType Channel ) ;
void Gpt_DisableNotification( Gpt_ChannelType Channel ) ;
void OSTick_CallBack( void );

/** PIT Channel 0 ISR --> Main CPU  */
#pragma CODE_SEG __NEAR_SEG NON_BANKED
	void interrupt  vfnPIT_Channel0_Isr(void);
	void interrupt  vfnPIT_Channel1_Isr(void);
	void interrupt  vfnPIT_Channel2_Isr(void);
	void interrupt  vfnPIT_Channel3_Isr(void);	
#pragma CODE_SEG DEFAULT


#endif /* GPT_H */ 